#include <stdio.h>
#include <string.h>

	int  shu[100005];
	int  pre[100005];
	int tail[100005];
main()
{
	int n;
	int i,j;
	double tot=0,max=0,l=0;
	while (1)
	{
		scanf("%d", &n);
		if (n==0) break;
		memset(shu,0,sizeof(shu));
//		memset(pre,0,sizeof(pre));
//		memset(tail,0,sizeof(tail));
		for (i=1;i<=n;i++)
			scanf("%d", &shu[i]);
		
		
		shu[0]=shu[n+1]=-1;

		for (i=1;i<=n;i++)
		{
			j=i;
			while (shu[i]<=shu[j-1])
				j=pre[j-1];
			pre[i]=j;
		}

		for (i=n;i>=1;i--)
		{
			j=i;
			while (shu[i]<=shu[j+1])
				j=tail[j+1];
			tail[i]=j;
		}
/*		
		for (i=1;i<=n;i++)
			printf("%d ", pre[i]);
		printf("\n");
		for (i=1;i<=n;i++)
			printf("%d ", tail[i]);
		printf("\n\n");

*/			
		max=shu[1];
		for (i=1;i<=n;i++)	
			{
				
				l=-pre[i]+tail[i]+1;
				tot=l*shu[i];
				if (tot>max) max=tot;
				
		}
		printf("%.0lf\n", max);
	}
	return 0;
}
